package com.vhr.controller;

import com.vhr.VO.DepartmentCountVO;
import com.vhr.VO.DeptEmpVO;
import com.vhr.entities.Department;
import com.vhr.entities.Result;
import com.vhr.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(description = "部门信息模块")
@RequestMapping("/api/dep")
public class DepartmentController {

    @Autowired
    private IDepartmentService iDepartmentService;

    /*统计部门信息:访问：http://localhost:8080/dep/countByDeptId */
    @ApiOperation("管理员：统计部门信息")
    @GetMapping("/countByDeptId")
    public Result countByDeptId(){
        List<DepartmentCountVO> results = iDepartmentService.countByDeptId();
        if(results==null){
            return Result.fail();
        }else {
            return Result.success().add("depList",results);
        }
    }

    /*显示部门名称及相应员工*/
    @ApiOperation("管理员统一接口：显示部门名称及相应员工")
    @GetMapping("/selectByDept")
    public Result selectByDept(){
        List<DeptEmpVO> deptEmpVOList = iDepartmentService.getEmpByDept();
        if(deptEmpVOList.size()==0){
            return Result.fail();
        }else {
            return Result.success().add("deptList",deptEmpVOList);
        }
    }

    /*管理员：显示部门名称*/
    @ApiOperation("管理员：显示部门名称")
    @GetMapping("/getDeptName")
    public Result getDeptName(){
        List<Department> list = iDepartmentService.getDeptName();
        if(list!=null){
            return Result.success().add("deptNameList",list);
        }else {
            return Result.fail();
        }
    }
}
